<template>
  <div>
    <div class="title">
      <div class="titleHint">
        <p>名称</p>
        <span>最多输入5个字符</span>
      </div>
      <div>序号</div>
      <div>开关</div>
    </div>
    <!-- 编辑 -->
    <div class="subject2">
      <div class="subjectBlock">
        <div>
          <input
            class="input"
            v-model="form.seatName"
            :value="form.seatName"
            maxlength="5"
            @change="seatNameChange"
          >
        </div>
        <div>
          <input
            class="input"
            v-model="form.seatSort"
            :value="form.seatSort"
            maxlength="5"
            type="number"
            @change="seatSortChange"
          >
        </div>
        <div>
          <i-switch
            :value="form.vacancy === 'Y' ? false : true "
            @change="onChange"
            slot="footer"
          ></i-switch>
        </div>
      </div>
    </div>
    <div class="kong"></div>
    <div class="buttonBox">
      <button
        @click="handleClick"
        type="primary"
        size="small"
        class="buttonBtn"
      >完成</button>
    </div>
  </div>
</template>

<script>
import { UPDATE_SHOP_SEAT_API } from '@/api'
import { getCurrentPageParams } from '@/utils'

export default {
  components: {},
  data () {
    return {
      form: {}
    }
  },
  created () {},
  computed: {
    account () {
      return this.$cookie.get('account')
    }
  },
  onShow () {
    this.init()
  },
  methods: {
    onChange () {
      const vm = this
      if (vm.form.vacancy === 'Y') {
        vm.form.vacancy = 'N'
        // 和之前开关不同了，现在注释了
        // vm._setvacancy(vm.vacancy)
      } else {
        vm.form.vacancy = 'Y'
        // vm._setvacancy(vm.form.vacancy)
      }
    },
    _setvacancy (vacancy) {
      const vm = this
      let params = {
        seatId: vm.form.seatId,
        shopId: vm.account.shopId,
        vacancy: vacancy
      }
      UPDATE_SHOP_SEAT_API(params)
        .then(r => {
          if (r.data.code === '0' && r.data.data) {
            vm.$toast('座位状态更新成功~~~')
          } else {
            vm.$toast(r.data.message)
          }
        })
        .catch(e => {
          console.info(e)
        })
    },
    handleClick () {
      const vm = this
      let params = {
        seatId: vm.form.seatId,
        seatName: vm.form.seatName,
        seatSort: vm.form.seatSort,
        vacancy: vm.form.vacancy,
        shopId: vm.account.shopId
      }
      UPDATE_SHOP_SEAT_API(params)
        .then(r => {
          if (r.data.code === '0' && r.data.data) {
            vm.$alert('座位状态更新成功', '').then(() => {
              this.$router.go(-1)
            })
          } else {
            vm.$toast(r.data.message)
          }
        })
        .catch(e => {
          console.info(e)
        })
    },
    init () {
      const vm = this
      let val = JSON.parse(getCurrentPageParams('val'))
      vm.form = val
    }
  }
}
</script>

<style lang="scss">
@import 'static/styles/color.scss';
.title {
  display: flex;
  justify-content: space-between;
  align-content: center;
  width: 100%;
  height: 50px;
  div {
    width: 33.33%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 16px;
    color: #000;
  }
  .titleHint {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    span {
      font-size: 12px;
      color: #9b9b9b;
      position: absolute;
      bottom: 0;
    }
  }
}
.subject2 {
  .subjectBlock {
    display: flex;
    justify-content: space-between;
    align-items: center;
    .input {
      color: #606266;
      font-size: 14px;
      border: 1px solid #dcdfe6;
      border-radius: 4px;
      text-align: center;
      padding: 7px 15px;
      height: 30px;
      line-height: 30px;
    }
    div {
      width: 33.33%;
      height: 80px;
      font-size: 14px;
      color: #5f5f5f;
      display: flex;
      justify-content: center;
      align-items: center;
      span {
        width: 20px;
        height: 20px;
        font-size: 12px;
        background: #ff2d2d;
        color: #fff;
        display: block;
        line-height: 20px;
        text-align: center;
        border-radius: 50px;
        margin-right: 5px;
      }
      p {
        font-size: 12px;
        color: #ff2d2d;
      }
    }
    .updateItem {
      span {
        background: #3ece46;
      }
      p {
        color: #3ece46;
      }
    }
  }
}
.kong {
  height: 90px;
}
.buttonBox {
  width: 100%;
  height: 40px;
  position: fixed;
  bottom: 0;
  z-index: 2;
  .buttonBtn {
    width: 100%;
    border-radius: 0;
    text-align: center;
    vertical-align: middle;
    touch-action: manipulation;
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
    line-height: 40px;
    font-size: 14px;
    border: 0 !important;
    text-decoration: none;
    color: #fff !important;
    background: #508ff9;
  }
}
</style>
